package com.chen.test7;

public class FriendTest {
    public static void main(String[] args) {
        Friend[] arr = new Friend[4];

        Friend g1 = new Friend("张三", 1, "男", "篮球");
        Friend g2 = new Friend("李四", 2, "男", "排球");
        Friend g3 = new Friend("王五", 3, "男", "睡觉");
        Friend g4 = new Friend("赵六", 4, "男", "学习");

        arr[0] = g1;
        arr[1] = g2;
        arr[2] = g3;
        arr[3] = g4;

        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            Friend friend = arr[i];
            sum = sum + friend.getAge();
        }
        double avg = sum * 1.0 / arr.length;
        System.out.println("平均年龄是：" + avg);

        // 统计年龄比平均值低的有几个，打印他们的信息
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            Friend friend = arr[i];

            if (friend.getAge() < avg) {
                count++;
                System.out.println(friend.getName() + friend.getAge() + friend.getSex() + friend.getHobby());
            }
        }
        System.out.println(count + "个");
    }
}
